package com.cam.framework.system.menu.controller;

import com.cam.framework.system.menu.domain.SysMenuDTO;
import com.cam.framework.system.menu.entity.SysMenu;
import com.cam.framework.system.menu.service.SysMenuService;
import com.cam.framework.utils.RestResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys/menu")
public class SysMenuController {

    private final SysMenuService sysMenuService;

    public SysMenuController(SysMenuService sysMenuService) {
        this.sysMenuService = sysMenuService;
    }

    @GetMapping("findById")
    public RestResult findById(String id) {
        SysMenuDTO sysMenuDTO = sysMenuService.findById(id);
        return RestResult.success().put("data", sysMenuDTO);
    }

    @PostMapping("/save")
    public String save(@RequestBody SysMenu sysMenu) {
        sysMenuService.saveOrUpdate(sysMenu);
        return "保存成功";
    }

    @PostMapping("/findList")
    public List<SysMenu> findList (@RequestBody SysMenu sysMenu) {
        return sysMenuService.list();
    }

    @PostMapping("/findPage")
    public RestResult findPage(@RequestBody SysMenu sysMenu) {
        List<SysMenu> page = sysMenuService.list();
        return RestResult.success().put("page", page);
    }
}
